import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2025-07-19
 * Time: 23:12
 */
public class Test65 {
    // 看成一个一维矩阵
//    输入：matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3
//    输出：true
    public static boolean searchMatrix(int[][] matrix, int target) {
        int m = matrix.length, n = matrix[0].length;
        int left = 0, right = m * n - 1;
        while(left <= right) {
            int mid = left + (right-left) / 2;
            if(matrix[mid/n][mid%n] == target) {
                return true;
            }else if(matrix[mid/n][mid%n] < target) {
                left = mid+1;
            }else {
                right = mid-1;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int n = sc.nextInt();
        int[][] t = new int[m][n];
        for(int i = 0; i < m; i++) {
            for(int j = 0; j < n; j++) {
                t[i][j] = sc.nextInt();
            }
        }
        int target = sc.nextInt();
        boolean ret = searchMatrix(t,target);
        System.out.println(ret);
    }
}
